package com.tencreat.common.config;

import cn.hutool.json.JSONObject;
import com.tencreat.common.core.domain.entity.SysDictData;
import com.tencreat.common.utils.DictUtils;
import lombok.Data;

import java.util.List;

/**
 * minio配置
 *
 * @Author SLT
 * @Company: 深圳腾创互联科技有限公司
 * @link: https://tencreat.com
 * @Date: 2022/3/1 15:23
 */
@Data
public class MinioConfig {
    private String endpoint;
    private String bucketName;
    private String accessKey;
    private String secretKey;
    private String accessUrl;

    public static MinioConfig getMinioConfig(){
        MinioConfig minioConfig = new MinioConfig();
        List<SysDictData> config = DictUtils.getDictCache("minio");
        System.out.println(new JSONObject(config).toString());
        for (SysDictData i : config) {
            if("endpoint".equals(i.getDictLabel())){
                minioConfig.endpoint = i.getDictValue();
            }
            if("bucketName".equals(i.getDictLabel())){
                minioConfig.bucketName = i.getDictValue();
            }
            if("accessKey".equals(i.getDictLabel())){
                minioConfig.accessKey = i.getDictValue();
            }
            if("secretKey".equals(i.getDictLabel())){
                minioConfig.secretKey = i.getDictValue();
            }
            if("accessUrl".equals(i.getDictLabel())){
                minioConfig.accessUrl = i.getDictValue();
            }
        }
        return minioConfig;
    }
}
